package com.photoeditor.demo.ui.widget.image.edit;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

import com.common.base.ui.widget.ripple.RippleImageView;
import com.photoeditor.R;

/**
 * Created by Administrator on 2017/8/15 0015.
 */

public class StickerSettingTopView extends RelativeLayout implements View.OnClickListener {

    RippleImageView mUndoBtn;
    RippleImageView mResetBtn;
    RippleImageView mOriginBtn;

    private StickerTopTabListener mStickerTopTabListener;

    public StickerSettingTopView(Context context) {
        this(context, null);
    }

    public StickerSettingTopView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StickerSettingTopView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mUndoBtn = (RippleImageView) findViewById(R.id.sticker_undo);
        mResetBtn = (RippleImageView) findViewById(R.id.sticker_reset);
        mOriginBtn = (RippleImageView) findViewById(R.id.sticker_origin);

        mUndoBtn.setOnClickListener(this);
        mResetBtn.setOnClickListener(this);
        mOriginBtn.setOnClickListener(this);
        mOriginBtn.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mStickerTopTabListener == null) {
                    return false;
                }
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    mStickerTopTabListener.onOriginClick(true);
                } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
                    mStickerTopTabListener.onOriginClick(false);
                }
                return false;
            }
        });
    }

    public void setOneStepBtnShow(boolean show) {
        if (show && mUndoBtn.getVisibility() != VISIBLE) {
            mUndoBtn.setVisibility(VISIBLE);
            mOriginBtn.setVisibility(VISIBLE);
        } else if (!show && mUndoBtn.getVisibility() == VISIBLE) {
            mUndoBtn.setVisibility(GONE);
            mOriginBtn.setVisibility(GONE);
        }
    }

    public void setTwoStepBtnShow(boolean show) {
        if (show && mResetBtn.getVisibility() != VISIBLE) {
            mResetBtn.setVisibility(VISIBLE);
        } else if (!show && mResetBtn.getVisibility() == VISIBLE) {
            mResetBtn.setVisibility(GONE);
        }
    }

    @Override
    public void onClick(View v) {
        if (mStickerTopTabListener == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.sticker_undo:
                mStickerTopTabListener.onUndoClick();
                break;
            case R.id.sticker_reset:
                mStickerTopTabListener.onResetClick();
                break;
        }
    }

    public void setStickerTopTabListener(StickerTopTabListener stickerTopTabListener) {
        mStickerTopTabListener = stickerTopTabListener;
    }

    public interface StickerTopTabListener {
        void onUndoClick();

        void onResetClick();

        void onOriginClick(boolean show);
    }
}
